package com.trkj.dao.jpa;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.LmbConsumptiveStock;

public interface LmbConsumptiveStockDAO extends CrudRepository<LmbConsumptiveStock,String>{
	@Query("select c from LmbConsumptiveStock c where c.cstocCid=?1 and c.cstocBatchNum=?2 ")
	public LmbConsumptiveStock findConStock(String cid,String batchnum);	

	@Query("select max(c.cstockId) from LmbConsumptiveStock c where c.cstockId like ?1%")
    public String findMaxID(String a);
	
	@Query("select c from LmbConsumptiveStock c where c.cstocWarehouseId = ?1")
	public List<LmbConsumptiveStock> findHcByWarehouseId(Pageable pageable,String ckId);
	
	@Query("select count(*) from LmbConsumptiveStock c where c.cstocWarehouseId = ?1")
	public long countHcByWarehouseId(String ckId);
	
	@Query("select c from LmbConsumptiveStock c where c.cstocWarehouseId = ?1")
	public List<LmbConsumptiveStock> findAllByWarehouseId(String ckId);
	
	@Query("select c from LmbConsumptiveStock c where c.cstocCname like ?1%")
	public List<LmbConsumptiveStock> findAllByCname(Pageable pageable,String cName);
	
	@Query("select count(*) from LmbConsumptiveStock c where c.cstocCname like ?1%")
	public long countfindAllByCname(String cName);
	
	//根据耗材编号和批号查找库存数量
	@Query("select c.cstocNum from LmbConsumptiveStock c where c.cstocCid=?1 and c.cstocBatchNum=?2")
	public long findConStockNum(String cid,String batchnum);
	
	@Query("select c from LmbConsumptiveStock c ")
	public List<LmbConsumptiveStock> findAllKucun(Pageable pageable);
	
	@Query("select count(*) from LmbConsumptiveStock c")
	public long countfindAllKucun();
	
	@Query("select c from LmbConsumptiveStock c where c.cstocWarehouseId = ?1")
	public List<LmbConsumptiveStock> findKucunByckName(Pageable pageable,String id);
	
	@Query("select count(*) from LmbConsumptiveStock c where c.cstocWarehouseId = ?1")
	public long countfindKucunByckName(String id);
	
	@Query("select c from LmbConsumptiveStock c where c.cstocWarehouseId =?1 and c.cstocCid=?2 and c.cstocBatchNum=?3")
	public LmbConsumptiveStock findByConStock(String ckId,String cid,String batchnum);
}
